package com.bigknow.appstore.web.base.service.impl;

import com.bigknow.appstore.web.base.entity.FusionConfig;
import com.bigknow.appstore.web.base.service.IFusionService;
import com.bigknow.appstore.web.base.service.ISystemConfigService;
import org.mongodb.morphia.Datastore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by 李科风 on 2016-09-14.
 */
@Service
public class SystemConfigService implements ISystemConfigService {

    @Autowired
    private Datastore ds;

    @Autowired
    private IFusionService fusionService;

    @Override
    public FusionConfig getFusionConfig() {
        FusionConfig cfg = ds.find(FusionConfig.class).get();
        if (cfg == null) {
            cfg = new FusionConfig();
        }
        return cfg;
    }

    @Override
    public void saveFusionConfig(FusionConfig cfg) {
        ds.findAndDelete(ds.find(FusionConfig.class));
        ds.save(cfg);
        fusionService.init(cfg);
    }
}
